home *** CD-ROM | disk | FTP | other *** search
- Path: phoenix.csc.calpoly.edu!not-for-mail
- From: nbonfili@phoenix.csc.calpoly.edu (Nicholas R Bonfilio)
- Newsgroups: comp.lang.c++
- Subject: Function Prototypes in C++
- Date: 3 Apr 1996 12:40:26 -0800
- Organization: California Polytechnic State University at San Luis Obispo
- Message-ID: <4junnq$2k1@phoenix.csc.calpoly.edu>
- NNTP-Posting-User: nbonfili@phoenix.csc.calpoly.edu
-
- I know that function prototypes are required in standard C++ as opposed to C
- where they are not required. But, what I don't know for certain is the rules
- regarding the scoping of function protos...
-
- That is, can I declare the prototypes as "global": external to the main()
- routine?
-
- Should all prototypes go inside of the main() routine?
-
- Or should the prototypes be placed inside of each routine where the
- particular function is called? (This could have been asked in the C lang
- discussion group, I realize.)
-
- An example:
- -----------------------------------------------------------------------------
-
- int i = 4,
- j = 5,
- k = 4;
-
- main()
- {
- real result;
-
- result = average(i,j,k);
- cout << "Here is the answer: " << result << endl;
- }
-
-
- real average(int a, int b, int c)
- {
- return (sum(a,b,c)/3.0);
- }
-
-
- int sum(int x, int y, int z)
- {
- return x+y+z;
- }
-
- -----------------------------------------------------------------------------
- Where would the prototypes for each function go?
- All in main?
- All external to main?
- or should sum's go in average and average's in main?
-
- --
-
- TTYL, Nick
- (nbonfili@galaxy.csc.calpoly.edu)
-
-